import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class WindowGame extends JFrame {
   RandomNumber randomNumber;   //负责提供随机数的对象
   JTextField inputGuess;        //提供用户输入猜测的文本框
   JTextField hintText;          //提示有关信息    
   JButton getNumber,enterGuess;  
   ListenNumber listenNumber;  //getNumber按钮的监视器 
   ListenGuess listenGuess;   //enterGuess按钮的监视器 
   public WindowGame() { 
      init();
      setBounds(100,100,280,150);
      setVisible(true);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }
   void init() {
      setLayout(new FlowLayout());
      getNumber=new JButton("得到一个随机数");
      add(getNumber);
      randomNumber=new RandomNumber();
      hintText=new JTextField("输入你的猜测：",10);
      hintText.setEditable(false);
      inputGuess=new JTextField("0",10); 
      add(hintText);
      add(inputGuess);
      enterGuess=new JButton("确定"); 
      add(enterGuess);
      listenNumber=new ListenNumber();
      listenGuess=new ListenGuess();  
      getNumber.addActionListener(listenNumber);
      enterGuess.addActionListener(listenGuess);
      listenNumber.setRandomNumber(randomNumber);
      listenNumber.setHintJTextField(hintText);
      listenNumber.setInputJTextField(inputGuess);
      listenGuess.setRandomNumber(randomNumber);
      listenGuess.setHintJTextField(hintText);
      listenGuess.setInputJTextField(inputGuess);
   }
}


